package com.hxgis.oc.ncep.base;

public class NcepUrlGenerator {
    private final static String gfs_host = "https://nomads.ncep.noaa.gov/";
    private final static String gfs_url = "cgi-bin/filter_gfs_{RES}.pl?file=gfs.t{GFS_TIME}z.pgrb2.{RES}.f000&{LEVEL}&subregion=&{BBOX}&dir=%2Fgfs.{GFS_DATE}%2F{GFS_TIME}%2Fatmos";
    private final static String RES = "0p25"; //0p25, 0p50 or 1p00
    private final static String BBOX = "leftlon=0&rightlon=360&toplat=90&bottomlat=-90";

    public static String generateUrl(String requestLevelParam,
                                     String requestDateParam,
                                     String requestHourParam,
                                     String requestVarParam){
        String url = gfs_host + gfs_url;
        url = url.replace("{RES}", RES);
        url = url.replace("{BBOX}",BBOX);
        url = url.replace("{LEVEL}", requestLevelParam);
        url = url.replace("{GFS_DATE}", requestDateParam);
        url = url.replace("{GFS_TIME}", requestHourParam);
        url += requestVarParam;
        return url;
    }

    public static String generateRawFileName(String requestLevelParam,
                                             String requestDateParam,
                                             String requestHourParam,
                                             String requestVarParam)
    {
        String fileName = requestDateParam + requestHourParam + "_" + requestLevelParam + requestVarParam;
        fileName = fileName.replaceAll("&", "_");
        fileName = fileName.replaceAll("=", "_");
        fileName = fileName.replaceAll("_on", "");
        fileName = fileName.replaceAll("_var", "");
        return fileName + ".grb2";
    }
}
